﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.Data;

namespace PTTPOS_Solution.DAL
{
    public static class Categories_DA
    {
        public static DataTable ListCatagories=new DataTable();
        public static void GetListCatagories()
        {
            MySqlCommand com = new MySqlCommand("select * from tblcategories", Connection_PTTPOS.GetConnection());
            com.Connection.Open();
            MySqlDataAdapter da=new MySqlDataAdapter(com);
            ListCatagories.Clear();
            da.Fill(ListCatagories);
            com.Connection.Close();
        }

        public static string findCategoryByCategoryID(string id)
        {
            string str = "";
            MySqlCommand com = new MySqlCommand("select * from tblcategories where id=@id", Connection_PTTPOS.GetConnection());
            com.Parameters.AddWithValue("@id", id);
            com.Connection.Open();
            MySqlDataReader reader = com.ExecuteReader();
            if (reader.Read())
            {
                str = reader["id_print"].ToString();
            }
            com.Connection.Close();
            return str;
        }

        public static void UpdateCategory(string id, string id_print)
        {
            MySqlCommand com = new MySqlCommand("update tblcategories set id_print=@id_print where id=@id", Connection_PTTPOS.GetConnection());
            com.Parameters.AddWithValue("@id_print", id_print);
            com.Parameters.AddWithValue("@id", id);
            com.Connection.Open();
            com.ExecuteNonQuery();
            com.Connection.Close();
        }
    }
}
